package com.ddone.datax.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author ddone
 * @date 2024/5/19-19:31
 */
public class PropertiesLoader {

    private final Properties properties;

    public PropertiesLoader(String propertiesFileName) {
        properties = new Properties();
        try (InputStream input = getClass().getClassLoader().getResourceAsStream(propertiesFileName)) {
            if (input == null) {
                throw new IllegalArgumentException("Properties file not found: " + propertiesFileName);
            }
            properties.load(input);
        } catch (IOException ex) {
            throw new RuntimeException("Error reading properties file: " + propertiesFileName, ex);
        }
    }
    public String getProperty(String key) {
        return properties.getProperty(key);
    }

    public String getProperty(String key, String defaultValue) {
        return properties.getProperty(key, defaultValue);
    }

    public static void main(String[] args) {
        PropertiesLoader loader = new PropertiesLoader("kafka.properties");
        System.out.println(loader.getProperty("kafka.bootstrap.servers"));
    }
}
